<?php
/**
 * Notes:
 * Created by PhpStorm.
 * Author: TS
 * Date: 2019/10/4
 * Time: 13:21
 */

namespace app\model;


use think\Model;

class Task extends Model
{
    public function add($data){
        return self::create($data);
    }
    public function edit($task_id,$data){
        return self::update($data,['task_id' => $task_id]);
    }
    public function getById($task_id){
        return self::get($task_id);
    }
    public function getByIdAndUser($task_id,$user_id){
        return self::get([
            'task_id' => $task_id,
            'task_target' => $user_id
        ]);
    }
    public function getMyTask($user_id){
        return self::join('users','users.user_id = task.user_id')
            ->join('user_real','task.user_id = user_real.user_id')
            ->where(['task_target' => $user_id])
            ->field([
                'task_title,task_id,task_content,task_status,task.user_id,task_start as start_time,task_end as end_time,task_target,release_time,'
                .'user_header,task_progress,user_real.real_name'
            ])
            ->select();
    }
    public function getTaskData($task_id){
        return self::join('users','users.user_id = task.user_id')
            ->join('user_real','task.user_id = user_real.user_id')
            ->where(['task.task_id' => $task_id])
            ->field([
                'task_title,task_id,task_content,task_status,task.user_id,task_start as start_time,task_end as end_time,task_target,release_time,'
                .'user_header,task_progress,user_real.real_name as master_name,task.task_target as target_name'
            ])
            ->find();
    }
    public function getMyRelease($user_id){
        return self::join('users','users.user_id = task.user_id')
                    ->join('user_real','task.task_target = user_real.user_id')
                    ->where(['task.user_id' => $user_id])
                    ->field([
                        'task_title,task_id,task_content,task_status,task.user_id,task_start as start_time,task_end as end_time,task_target,release_time,'
                        .'user_header,task_progress,user_real.real_name'
                    ])
                    ->select();
    }
    public function getStartTimeAttr($value){
        return date('m-d',$value);
    }

    public function getEndTimeAttr($value){
        return date('m-d',$value);
    }

}